N=2
C=5
v=[1,2]
w=[1,2]
def Completely_backpack(N,C,v,w):
    #设置状态转移矩阵
    dp=[[0 for _ in range(C+1)] for _ in range(N)]
    #第一行状态
    for i in range(C+1):
        if i<v[0]:
            dp[0][i]=0
        if i>=v[0]:
            dp[0][i]=int(i/v[0])*w[0]
    #处理剩余行状态
    for i in range(1,N):
        for j in range(C+1):
            maxValue=dp[i-1][j]
            k=1
            while k*v[i]>=0 and k*v[i]<=j:
                if dp[i-1][j-k*v[i]]+w[i]*k>maxValue:
                    maxValue=dp[i-1][j-k*v[i]]+w[i]*k
                k+=1
            dp[i][j]=maxValue
    print(dp[N-1][C])
Completely_backpack(N,C,v,w)